jQuery(function($){
	
	$('.theme-popover-mask').fadeIn(100);
	$('.theme-popover').slideDown(200);
		
	//点击更换验证码
	$("#verify_img").click(function(){
		var url = baseContextPath + "ajax/getvalidateCode";
		$.get(url,function(data){
			$("#verify_img").attr("src",baseContextPath +"qrcode/"+data.path);
		});
	});
	
	$("#loginForm").validate({
		submitHandler:function(form){
			var loginUrl = $("#loginForm").attr("action");
			var url = baseContextPath + "loginController/checkLogin";
			var loginName = $("#loginName").val();
			var password = $("#password").val();
			var isAutoLog = $("#isAutoLog").is(":checked");
			var validateCode = $("#validateCode").val();
			$.ajax({
				type:"post",
				url:url,
				dataType:"json",
				data:{loginName:loginName,password:password,isAutoLog:isAutoLog,validateCode:validateCode},
				async:false,
				error:function(xhr,status,err){
					alert("系统异常");
				},
				success:function(data){
					if(data.result == "success"){
						window.location.href = loginUrl;
					}else if(data.result == "errorCode"){
						alert(data.msg);
						var url = baseContextPath + "ajax/getvalidateCode";
						$.get(url,function(data){
							$("#verify_img").attr("src",baseContextPath +"qrcode/"+data.path);
						});
					}else if(data.result == "error"){
						alert(data.msg);
					}
				}
			});
		},
		rules:{
			loginName:{
				required:true,
				maxlength:30
			},
			password:{
				required:true,
				maxlength:30
			},
			validateCode:{
				required:true,
				maxlength:4
			}
		},
		messages:{
			loginName: {
				   required: "请输入用户名",
				   maxlength: "用户名不能超过30个字符"
			   },
			   password: {
				   required: "请输入密码",
				   maxlength: "密码不能超过30个字符"
			   },
			   validateCode: {
				   required: "请输入验证码",
				   maxlength: "请输入4位数字的验证码"
			   }
		},
		errorElement:"li",
		errorPlacement: function(error,element){
			error.appendTo(element.parent());
		}
	});
});

